#!/usr/bin/python
# coding:utf-8

import pymysql
from DBUtils.PooledDB import PooledDB
from contextlib import contextmanager

# 数据库连接池
pool = PooledDB(host='localhost', user='root', passwd='123456', db='umc', port=3306, charset="utf8",
                creator=pymysql, mincached=5, cursorclass=pymysql.cursors.DictCursor)


@contextmanager
def create_cursor():
    conn = pool.connection()
    cursor = conn.cursor()
    try:
        yield conn, cursor
    finally:
        cursor.close()
        conn.close()
